import React, { useEffect, useState } from 'react'
import http from '../../utils/http'
import styles from './index.module.css'
import { useNavigate } from 'react-router-dom'
function Index() {
    let [list, setList] = useState()
    let navigate = useNavigate()
    let getList = async () => {
        let res = await http.get('/api/order/list')

        console.log(res);

        let { code, data } = res.data

        if (code === 200) {
            setList(data)
        }

    }

    useEffect(() => {
        getList()
    }, [])

    const handleDetail = (val) => {
        navigate('/detail',{state:val})
    }
    return (
        <div>
            {
                list?.map((item, ind) => (
                    <div key={ind} className={styles.list_box}>
                        <div className={styles.list_left}>
                            <span>{item.start}</span>
                            <span>{item.startTime}</span>
                            <span>{item.end}</span>
                            <span>{item.endTime}</span>
                        </div>
                        <div className={styles.list_right}>
                            <span onClick={() => handleDetail(item)}>
                                {item.price}
                            </span>
                        </div>
                    </div>
                ))
            }
        </div>
    )
}

export default Index
